package CoreJAV;
import java.io.*;
import java.util.Scanner;

import javax.xml.parsers.*;

import org.w3c.dom.*;
import org.xml.sax.SAXException;
public class readXMLfile {
	static final String UNUSED = "unused";
	static final String UNUSED2 = readXMLfile.UNUSED;
	static final String UNUSED22 = readXMLfile.UNUSED2;
	private static Scanner input;
	public static void main(String[] args) {
        try {
            input = new Scanner(System.in);
            System.out.println("Nhap link File: ");
            //Vi du: D:\Study in university\3 grade year\Project I\tuan 4
            String fileName=input.nextLine();
            File xmlFile = new File(fileName);
            DocumentBuilder dBuilder;
            dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);
            System.out.println("Root element : " + doc.getDocumentElement().getNodeName());
            if (doc.hasChildNodes()) {
                printNote(doc.getChildNodes());
            }
            System.out.println("End Root element: " + doc.getDocumentElement().getNodeName());
        } catch (ParserConfigurationException | SAXException | IOException e) {
        }
    }
    private static void printNote(NodeList nodeList) {
        for (int count = 0; count < nodeList.getLength(); count++) {
            Node tempNode = nodeList.item(count);
            if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
                               tempNode.getNodeName();
                System.out.print(tempNode.getTextContent());
                if (tempNode.hasAttributes()) {
                    NamedNodeMap nodeMap = tempNode.getAttributes();
                    for (int i = 0; i < nodeMap.getLength(); i++) {
                        Node node = nodeMap.item(i);
                        node.getNodeName();
                        System.out.print(node.getNodeValue());
                    }
                }

                tempNode.getNodeName();
            }
        }
    }
}
